package cn.daichi.redisidempotency.config;


import cn.daichi.redisidempotency.interceptor.IdempotencyInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    private final IdempotencyInterceptor idempotencyInterceptor;

    public WebMvcConfig(IdempotencyInterceptor idempotencyInterceptor) {
        this.idempotencyInterceptor = idempotencyInterceptor;
    }

    /**
     * 实现 WebMvcConfigurer 中的添加拦截器方法
     *
     * @param registry 拦截器注册表
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //使用拦截器注册表进行添加 自定义拦截器
        registry.addInterceptor(idempotencyInterceptor)
                //添加拦截路径
                .addPathPatterns("/**");
    }

}
